<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 19-1-14
 * Time: 上午11:17
 */

namespace wechatapi\controllers;


use common\models\db\Smms;
use common\models\db\Tag;
use common\rewrite\deepziyu\yii_fast_api\Controller;
use GDText\Box;
use GDText\Color;
use yii\web\Response;

class PublicController extends Controller
{
    /**
     * public测试
     * @desc get/post
     * @param string $a moren xxx
     * @return array
     * @return string x test
     * @return string y y
     */
    public function actionIndex($a = 'xxx')
    {
        $r = [
            'a' => $a,
            'x' => 1,
            'y' => 1,
        ];
        return $r;
    }

    /**
     * [已弃用] 微信公众号服务器配置接入
     */
    public function actionWeiXinTokenConfigBak0()
    {
        //1. 将timestamp , nonce , token 按照字典排序
        $timestamp = $_GET['timestamp'];
        $nonce = $_GET['nonce'];
        $token = "wyii2";
        $signature = $_GET['signature'];
        $array = array($timestamp,$nonce,$token);
        sort($array);

        //2.将排序后的三个参数拼接后用sha1加密
        $tmpstr = implode('',$array);
        $tmpstr = sha1($tmpstr);

        //3. 将加密后的字符串与 signature 进行对比, 判断该请求是否来自微信
        if($tmpstr == $signature)
        {
            echo $_GET['echostr'];
            exit;
        }
    }

    /**
     * 微信公众号服务器配置接入
     * @desc https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432
     * @throws
     */
    public function actionWeiXinTokenConfig()
    {
        $wechat = \Yii::$app->easy_wechat;
        $wechat->app->server->push(function ($message){
            return "您好！欢迎使用 EasyWeChat!";
        });
        $resp = $wechat->app->server->serve();
        $resp->send(); exit;
    }
}